<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
    >
<meta charset="UTF-8">
<head th:include="include :: header"></head>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="query()">查询</button>
                        <button class="btn btn-success" onclick="resetParam()">重置</button>
                    </div>

                    <div class="columns pull-right col-md-2 nopadding">
                        <input class="form-control" type="text" id="name" placeholder="会员名称" tabindex="2"/>
                    </div>
                    <div class="columns pull-right col-md-4 nopadding">
                        <input class="form-control" type="text" id="idCardNo" placeholder="身份证号" tabindex="1"/>
                    </div>
                </div>
            </div>
            <table id="exampleTable" data-mobile-responsive="true">
            </table>
        </div>
    </div>
</div>
</div>
<!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
<div>
    <script type="text/javascript">
        var s_edit_h = 'hidden';
    </script>
</div>
<div shiro:hasPermission="mp:product:update">
    <script type="text/javascript">
        s_edit_h = '';
    </script>
</div>
<div>
    <script type="text/javascript">
        var s_edit_d = 'hidden';
    </script>
</div>
<div shiro:hasPermission="mp:product:del">
    <script type="text/javascript">
        s_edit_d = '';
    </script>
</div>

</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">

    var prefix = "/mp/member";
    $(function () {
        load();
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get', // 服务器数据的请求方式 get or post
                    url: prefix + "/list", // 服务器数据的加载地址
                    //showRefresh: true,
                    //	showToggle : true,
                    //	showColumns : true,
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: true, // 设置为true会有隔行变色效果
                    dataType: "json", // 服务器返回的数据类型
                    pagination: true, // 设置为true会在底部显示分页条
                    // queryParamsType : "limit",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    singleSelect: false, // 设置为true将禁止多选
                    // contentType : "application/x-www-form-urlencoded",
                    // //发送到服务器的数据编码类型
                    pageSize: 10, // 如果设置了分页，每页数据条数
                    pageNumber: 1, // 如果设置了分布，首页页码
                    //search : true, // 是否显示搜索框
                    showColumns: false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                    queryParams: function (params) {
                        return {
                            //说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            limit: params.limit,
                            offset: params.offset
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    columns: [
                        {
                            field: 'name',
                            title: '会员名称'
                        },
                        {
                            field: 'idCardNo',
                            title: '身份证号'
                        },
                        {
                            field: 'phone',
                            title: '手机号'
                        },
                        {
                            field: 'regTime',
                            title: '注册时间'
                        },
                        {
                            field: 'isVip',
                            title: '是否Vip(已充值)',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-info">否</span>';
                                } else if (value == '1') {
                                    return '<span class="label label-success">是</span>';
                                }
                            }
                        },
                        {
                            field: 'vipLevel',
                            title: 'Vip级别',
                            formatter: function (value, row, index) {
                                if (value == '1') {
                                    return '<span class="label label-info">年Vip</span>';
                                } else if (value == '2') {
                                    return '<span class="label label-success">终生Vip</span>';
                                }
                            }
                        },
                        {
                            field: 'rechargeTime',
                            title: '充值时间'
                        },
                        {
                            field: 'expireDate',
                            title: 'Vip到期时间',
                            formatter: function (value, row, index) {
                                var dtl = '';
                                if (row.vipLevel == 1) {
                                    dtl = '<span class="label label-info">'+value+'</span>';
                                }else if (row.vipLevel == 2) {
                                    dtl = '<span class="label label-info">终生</span>';
                                }
                                return dtl;
                            }
                        },
                        /*{
                            field: 'inviteNum',
                            title: '邀请人数'
                        },
                        */
                        {
                            title: '操作',
                            field: 'memberId',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var dtl = '';
                                if (row.isVip == 0) {
                                    dtl = '<a class="btn btn-success btn-sm " href="#" mce_href="#" title="升级VIP" onclick="toSetVip(\''
                                        + value
                                        + '\')"><i class="fa fa-address-card-o"></i>升级VIP</a> ';
                                }else if (row.isVip == 1) {
                                    dtl = '<a class="btn btn-success btn-sm " href="#" mce_href="#" title="取消VIP" onclick="cancelVip(\''
                                        + value
                                        + '\')"><i class="fa fa-address-card-o"></i>取消VIP</a> ';
                                }
                                var r = '<a class="btn btn-success btn-sm " href="#" mce_href="#" title="删除" onclick="remove(\''
                                    + value
                                    + '\')"><i class="fa fa-address-card-o"></i>删除</a> ';
                                return dtl + r;
                            }
                        }]
                });
    }

    function query() {
        var opt = {
            query: {
                name: $('#name').val(),
                idCardNo: $('#idCardNo').val(),
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }

    function resetParam() {
        $('#name').val('');
        $('#idCardNo').val('');
        reLoad();
    }


    function reLoad() {
        var opt = {
            query: {
                limit: 10,
                offset: 0
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }


    function toSetVip(memberId) {
        layer.open({
            type: 2,
            title: '升级VIP',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['400px', '300px'],
            content: prefix + '/toSetVip/' + memberId// iframe的url
        });
    }

    function cancelVip(memberId) {
        layer.confirm('确定取消VIP吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: prefix + "/cancelVip",
                type: "post",
                data: {
                    'memberId': memberId
                },
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg(r.msg);
                        $('#exampleTable').bootstrapTable('refresh');
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        })
    }


    function remove(memberId) {
        layer.confirm('确定删除该会员吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: prefix + "/removeMember",
                type: "post",
                data: {
                    'memberId': memberId
                },
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg(r.msg);
                        $('#exampleTable').bootstrapTable('refresh');
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        })
    }

    function commission(memberId) {
        layer.open({
            type: 2,
            title: '佣金统计',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '720px'],
            content: prefix + '/commissionIndex/' + memberId// iframe的url
        });
    }

    function edit(id) {
        layer.open({
            type: 2,
            title: '编辑',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['850px', '420px'],
            content: prefix + '/getMember/' + id// iframe的url
        });
    }
</script>
</body>

</body>
</html>